//
//  LableAndTextField.m
//  YYPHSpeedJump
//
//  Created by sujiang on 15/12/17.
//  Copyright © 2015年 sujiang. All rights reserved.
//

#import "LableAndTextField.h"

@interface LableAndTextField ()<UITextFieldDelegate>
{
    UIView *aView;
    
}
@property (nonatomic, strong) NSString *placeHolder;


@end

@implementation LableAndTextField

- (instancetype)initWithFrame:(CGRect)frame lableText:(NSString *)text placeHolderText:(NSString *)placeHolder
{
    self = [super initWithFrame:frame];
    if (self) {
        CGFloat height = frame.size.height;
        CGFloat width = frame.size.width;
        self.lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 57, height)];
        aView = [[UIView alloc] initWithFrame:CGRectMake(self.lable.right, 0, 1, height)];
        aView.backgroundColor = kColors(229, 229, 229, 1);
        aView.alpha = 0.5;
        self.textField = [[UITextField alloc] initWithFrame:CGRectMake(aView.right + 20, 3.5, width - aView.right, height)];
        self.textField.returnKeyType = UIReturnKeyDone;
        self.lable.text = text;
        self.textField.placeholder = placeHolder;
        self.lable.textAlignment = NSTextAlignmentCenter;
        self.lable.textColor = kColors(218, 166, 46, 1);
        [self addSubview:self.lable];
        [self addSubview:aView];
        [self addSubview:self.textField];
        [self.textField setValue:kColors(131, 131, 131, 1) forKeyPath:@"_placeholderLabel.textColor"];
        [self.textField setValue:[UIFont boldSystemFontOfSize:12] forKeyPath:@"_placeholderLabel.font"];
        
        self.textField.delegate = self;
    
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    self.placeHolder = textField.placeholder;
    textField.placeholder = nil;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if ([textField.text isEqualToString:@""]) {
        textField.placeholder = self.placeHolder;
    }
}


@end
